#
# @lc app=leetcode.cn id=145 lang=python3
#
# [145] 二叉树的后序遍历
#
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
# @lc code=start
# Definition for a binary tree node.

from typing import List, Optional

class Solution:
    def postorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
        self.arr = []
        self.postorder(root)
        return self.arr
    
    def postorder(self, root: TreeNode) -> None:
        if root is None:
            return
        self.postorder(root.left)
        self.postorder(root.right)
        self.arr.append(root.val)
# @lc code=end

